<?php

namespace app\crm\controller;

use app\crm\model\Task as TaskModel;
use app\crm\model\User as UserModel;
use think\Db;

class Index extends BaseController
{
    public function index()
    {
        $this->assign('manage_user', session('manage_user'));
        return $this->fetch();
    }

//    public function login()
//    {
//        $data = input('post.');
//        $name = $data['username'];
//        $pwd = $data['password'];
//        $info = Db::name('admin')->where(['name' => $name])->find();
//        $enc_pwd = enc_pwd($pwd, $info['salt']);
//        if ($enc_pwd != $info['password']) {
//            return json(['errorCode' => 1, 'msg' => '账号密码不正确']);
//        }
//        session('manage_user', $info['name']);
//        session('manage_id', $info['id']);
//        return json(['errorCode' => 0, 'msg' => '登录成功']);
//    }

//    public function logout()
//    {
//        session('manage_user',null);
//        session('manage_id',null);
//    }

    public function welcome()
    {
        $bonus_pool = Db::name('config_param')->where('key', 'bonus_pool')->value('value');
        $user = (new UserModel());
        $count_user = $user->count('id');
        $count_user_today = $user->whereTime('add_time', 'today')->count('id');
        $task = (new TaskModel());
        $count_task = $task->count('id');
        $count_task_today = $task->whereTime('add_time', 'today')->count('id');
        $this->assign('manage_user', session('manage_user'));
        $this->assign('bonus_pool', $bonus_pool);
        $this->assign('count_user', $count_user);
        $this->assign('count_user_today', $count_user_today);
        $this->assign('count_task', $count_task);
        $this->assign('count_task_today', $count_task_today);
        return $this->fetch();
    }
}